import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:multi_image_picker2/multi_image_picker2.dart';
import 'package:study_online/pages/discussPage/DiscussModel.dart';
import 'package:study_online/pages/discussPage/views/ItemBin.dart';
import 'package:study_online/pages/myPage/MyModel.dart';
import '../../main.dart';

class PublishProblemViewModel extends ChangeNotifier {
  void publishProblem(int couId, String stuId, String content,
      List<ItemBin> imgs, List<String> imgNames) async {
    String content1 = "";
    for (int i = 0; i < imgNames.length-1; ++i) {
      content1 +=
          "@@" + "http://192.168.43.173:8080/FileUpload/upload/" + imgNames[i];
      await uploadImgTomcat(imgs[i].asset, imgNames[i]);
    }
    Response result = await insertProblem(couId, stuId, content + content1);
    if (result.data["code"] == 0) {
      EasyLoading.showSuccess(result.data["msg"]);
      Navigator.of(navigatorKey.currentContext).pop();
    } else
      EasyLoading.showError(result.data["msg"]);
  }
}
